package unit14.blockingQueue;

import java.io.File;
import java.util.Enumeration;
import java.util.concurrent.BlockingQueue;

public class FileEnumerationTask implements Runnable{
	public static File DUMMY=new File("");
	private BlockingQueue<File> queue;
	private File startingDirectory;
	
	public FileEnumerationTask(BlockingQueue<File> queue, File startingDirectory) {
		this.queue = queue;
		this.startingDirectory = startingDirectory;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			Enumerate(startingDirectory);
			queue.put(DUMMY);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public void Enumerate(File startingDirectory2) throws InterruptedException{
		// TODO Auto-generated method stub
		File[] files=startingDirectory2.listFiles();
		for(File file:files){
			if(file.isDirectory())
				Enumerate(file);
			else
				queue.put(file);
		}
	}

}
